#include "Camera.h"

glm::mat4 Camera::getViewMatrix() const {
	return glm::lookAt(mPosition, mPosition + mFront, mUp);
}
void Camera::processKeyboard(MOVE_DIRECTION direction) {
	if (direction == MOVE_DIRECTION::FRONT) {
		mPosition += mSpeed * mFront;
	}
	else if (direction == MOVE_DIRECTION::BACK) {
		mPosition -= mSpeed * mFront;
	}
	else if (direction == MOVE_DIRECTION::LEFT) {
		mPosition -= glm::normalize(glm::cross(mFront, mUp)) * mSpeed;
	}
	else if (direction == MOVE_DIRECTION::RIGHT) {
		mPosition += glm::normalize(glm::cross(mFront, mUp)) * mSpeed;
	}
}
void Camera::processMouseMovement(double xPos, double yPos) {
	if (mFirstMove) {
		mPreXPos = xPos;
		mPreYPos = yPos;
		mFirstMove = false;
		return;
	}
	else {
		double deltaYaw = (xPos - mPreXPos) * mSensitivity;
		double deltaPitch = (yPos - mPreYPos) * mSensitivity;
		mPreXPos = xPos;
		mPreYPos = yPos;
		mYawDegree = deltaYaw + mYawDegree;
		mPitchDegree = deltaPitch + mPitchDegree;
		std::cout << "mYawDegree=" << mYawDegree << ", mPitchDegree=" << mPitchDegree << std::endl;
		if (mYawDegree >= -1.0f) {
			mYawDegree = -1.0f;
		}
		else if (mYawDegree <= -179.0f) {
			mYawDegree = -179.0f;
		}
		if (mPitchDegree >= 89.0f) {
			mPitchDegree = 89.0f;
		}
		else if (mPitchDegree <= -89.0f) {
			mPitchDegree = -89.0f;
		}
		double yawRadian = glm::radians(mYawDegree);
		double pitchRadian = glm::radians(mPitchDegree);

		mFront.y = glm::sin(pitchRadian);
		mFront.x = glm::cos(pitchRadian) * glm::cos(yawRadian);
		mFront.z = glm::cos(pitchRadian) * glm::sin(yawRadian);
		mFront = glm::normalize(mFront);
	}
}
